<?php
/**
 * @Author: Administrator
 * @Date:   2014-09-22 23:01:16
 * @Last Modified by:   Administrator
 * @Last Modified time: 2014-11-19 00:35:48
 */

class OpusModel extends CommentModel
{
	//定义主表
	public $table = 'opusdata';
	
	public function add_($data)
	{
		return $this->add($data);
	}
	
	public function get_opus_db()
	{
		return $this->order('opusid DESC')->all();
	}
	public function get_one_opus($where,$field=null)
	{
		return $this->where($where)->field($field)->find();
	}
	public function del_opus($opusid){
		//1.主表
		$where = array('opusid'=>$opusid);
		//删除缩略图-------
		$thumbPath = $this->get_one_opus($where,'opus_thumb');
		$thumbPath = $thumbPath['opus_thumb'];
		//组合完整路径
		$thumbFullPath = ROOT_PATH . $thumbPath;
		if(is_file($thumbFullPath)){
			//删除缩略图
			unlink($thumbFullPath);
			//获得源图路径
			$sourcePath = str_replace(C('THUMB_ENDFIX'), '', $thumbFullPath);
			//删除源图
			if(is_file($sourcePath)) unlink($sourcePath);
		} 
		//删除主表
		return $this->where(array('opusid'=>$opusid))->delete();
	}
	
}